import axios from 'axios'
import { getToken } from '@/utils/auth' // 添加这行导入

const service = axios.create({
  baseURL: 'http://localhost:8000',
  timeout: 5000
})

service.interceptors.request.use(
  config => {
    const token = getToken() // 现在 getToken 已定义
    if (token) {
      config.headers['Authorization'] = `Bearer ${token}`
    }
    return config
  },
  error => Promise.reject(error)
)

export default service